import {Modal, Button} from 'antd';
import {inject, observer} from "mobx-react";
import {toJS} from 'mobx';
import {
  WeaTab,
  WeaAuth,
  WeaLocaleProvider,
  WeaButtonIcon
} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import {WeaSwitch} from 'comsMobx'
import {WeaTableNew} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;

import * as blogUtil from '../../../util/index';

@inject('blogShareSetting')
@observer
export default class ShareSetting extends React.Component {
  constructor(props){
    super(props);
    this.state={}
  }

  componentDidMount() {
    this.props.blogShareSetting.doInit();
  }

  onOperatesClick = (record, index, operate) => {
    const {blogShareSetting} = this.props;
    if(operate.index == '0'){//编辑
      blogShareSetting.getBlogShareSetEditCondition({shareId: record.id});
      blogShareSetting.setState({editShareVisible: true,shareId:record.id});
    }
    if(operate.index == '1'){//删除
      if(record.type==7){
        blogUtil.doConfirm(getLabel(384544,'删除申请人将清除这些人对您的关注')+','+getLabel(82017,'确认删除？'), () => blogShareSetting.operateBlogShareSet({operation: 'delShare', id: record.id, shareType:record.type}));
      }else{
        blogUtil.doConfirm(getLabel(82017,'确认删除？'), () => blogShareSetting.operateBlogShareSet({operation: 'delShare', id: record.id, shareType:record.type}));
      }
      
    }
  }

  render() {
    const {blogShareSetting} = this.props;
    const {selectedKey, addShareVisible, addShareCondition, editShareCondition, editShareVisible, shareId} = toJS(blogShareSetting.status);
    const selectedRowKeys = toJS(blogShareSetting.myShareTable.selectedRowKeys);
    const tabs = [
      {
        groupid: 'defaultShare',
        title: getLabel(381919,'默认分享'),
        viewcondition: '1'
      },
      {
        groupid: 'myShare',
        title: getLabel(33310,'我的分享'),
        viewcondition: '2'
      },
    ]

    return (
      <div style={{height: '100%'}} className='wea-blog-setting-share'>
        <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@cgc549`}
          type='card'
          datas={tabs}
          keyParam="viewcondition"
          countParam="groupid"
          selectedKey={selectedKey}
          onChange={v => blogShareSetting.setState({selectedKey: v})}
          buttons={selectedKey == 1 ? null :
            [
            <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@yij5wr@add`}
              buttonType='add'
              type="primary"
              onClick={() => {blogShareSetting.setState({addShareVisible: true})}}/>,
            <WeaButtonIcon ecId={`${this && this.props && this.props.ecId || ''}_WeaButtonIcon@k87uuf@del`}
              buttonType='del'
              type="primary"
              disabled={selectedRowKeys.length == 0}
              onClick={() => blogUtil.doConfirm(getLabel(82017,'确认删除？'), () => blogShareSetting.operateBlogShareSet({operation: 'delShare', id: selectedRowKeys.join(',')}))}/>
          ]}
        />
        {
          selectedKey == 1 ?
            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@473t67`}
              comsWeaTableStore={blogShareSetting.defaultShareTable}
              hasOrder={true}
              needScroll={true}
            /> :
            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@kcly2y`}
              comsWeaTableStore={blogShareSetting.myShareTable}
              hasOrder={true}
              needScroll={true}
              onOperatesClick={this.onOperatesClick}
            />
        }

        <WeaAuth ecId={`${this && this.props && this.props.ecId || ''}_WeaAuth@rb4jxg`}
          visible={addShareVisible}
          title={getLabel(384480,'添加分享')}
          conditions={addShareCondition}
          onOk={datas => {blogShareSetting.operateBlogShareSet({...datas, operation: 'saveShare'})}}
          onCancel={() => blogShareSetting.setState({addShareVisible: false})}
        />

        <WeaAuth ecId={`${this && this.props && this.props.ecId || ''}_WeaAuth@1j0rgf`}
          visible={editShareVisible}
          title={getLabel(384481,'编辑分享')}
          conditions={editShareCondition}
          onOk={datas => {blogShareSetting.operateBlogShareSet({...datas, id:shareId, operation: 'saveEdit'})}}
          onCancel={() => blogShareSetting.setState({editShareVisible: false})}
        />
      </div>
    )
  }
}